import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import px2rem from 'postcss-px2rem'; // 或者使用postcss-px2rem

// https://vite.dev/config/
export default defineConfig({
  base: './',
  resolve: {
    alias: {
      "@": path.resolve("./src"),
      '@public': path.resolve(__dirname, 'public') // 确保这里的路径正确
    }
  },
  plugins: [
    vue(),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      symbolId: 'icon-[dir]-[name]',
    }),
    AutoImport({
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  css: {
    postcss: {
      plugins: [
        px2rem({
          // 设计稿宽度，例如设计稿为750px
          // remUnit: 192 // 1rem = 75px
          remUnit: 37.5
        })
      ]
    }
  }
})
